<template>
  <div>
    <FormTable :formData="formData"
               :columnData="columnData"
               :url="$api.integral_coupon_getlist"
               :editData="editData"
               :new_url="this.$api.integral_coupon_insert"
               :detail_url="this.$api.integral_coupon_info"
               :edit_url="this.$api.integral_coupon_save"
               :is_default_edit="true"
               :pageConfig="pageConfig"></FormTable>
  </div>
</template>

<script>
export default {
  data () {
    return {
      formData: [
        {
          name: "title",
          label: "抵用券标题",
          value: "",
          type: "input",
        },
        {
          name: "display",
          label: "是否显示",
          value: '',
          type: "select",
          groups: [
            {
              label: '所有',
              value: ''
            },
            {
              label: '显示',
              value: 1
            },
            {
              label: '隐藏',
              value: 0
            },
          ]
        },
      ],
      columnData: [
        {
          prop: "integral_coupon_id",
          label: "id"
        },
        {
          prop: "title",
          label: "积分抵用券标题"
        },
        {
          prop: "integral",
          label: "兑换所需积分"
        },
        {
          prop: "limit_num",
          label: "领取次数限制"
        },
        {
          prop: "display",
          label: "是否显示",
          custom: true,
          type: 'switch',
          url: this.$api.integral_coupon_status
        },
        {
          prop: "sort",
          label: "排序",
          custom: true,
          type: 'input',
          url: this.$api.integral_coupon_sort
        },
        {
          prop: 'btn_group',
          label: '操作',
          custom: true,
          type: 'btn_group',
          width:'200px',
          group: [
            {
              name: '编辑',
              type: 'edit',
              color: 'primary',
              detail_mark: 'integral_coupon_id',
            },
            {
              name: '删除',
              type: 'delete',
              color: 'danger',
              url: this.$api.integral_coupon_status
            }
          ]
        }
      ],
      editData: [
        {
          name:'integral_coupon_id',
          label:'积分抵用券id',
          value:'',
          type:'input',
          display:'none'
        },
        {
          name: "coupon_id",
          label: "优惠券",
          value: '',
          type: "select",
          groups:[],
          config:{
            filterable:true
          },
          rules:[
            { required: true, message: "请选择优惠券", trigger: "blur" },
          ]
        },
        {
          name: 'integral',
          label: '所需积分',
          value: '',
          datatype:'number',
          type: 'input',
          rules:[
            { required: true, message: "请输入所需积分", trigger: "blur" },
            { type: 'number', message: '所需积分必须为数字值'},
          ]
        },
        {
          name: 'desc',
          label: '抵用券描述',
          value: '',
          type: 'textarea',
          rules:[
            { required: true, message: "请输入抵用券描述", trigger: "blur" },
          ]
        },
        {
          name: 'content',
          label: '抵用券说明',
          value: '',
          type: 'editor',
          width: 640,
          rules:[
            { required: true, message: "请输入抵用券说明", trigger: "blur" },
          ]
        },
        {
          name: 'limit_num',
          label: '限购数量',
          value: '',
          type: 'input',
          rules:[
            { required: true, message: "请输入限购数量", trigger: "blur" },
          ]
        },
        {
          name: 'sort',
          label: '排序',
          value: '',
          type: 'input',
        },
        {
          name: 'display',
          label: '是否显示',
          value: '',
          type: 'switch',
          config: {
            'active_value': '1',
            'inactive-value': '0'
          }
        },
      ],
      pageConfig: {
        page: 1,
        pagesize: 10,
      }
    };
  },
  created () {
    this.getCard();
  },
  methods: {
    getCard(){
      this.$req.get(this.$api.coupon_getnopagelist).then(res => {
        let data = res.data;
        for (var i in data) {
          this.editData[1].groups.push({
            label: data[i].title,
            value: data[i].coupon_id,
          })
        }
      })
    },
    handleSizeChange (e) {
      console.log(e);
    },
    handleCurrentChange (e) {
      console.log(e);
    },
    submit (e) {
      console.log(e);
    },
    reset (e) {
      console.log(e);
    }
  }
}
</script>

<style lang="scss" scoped>
</style>